import { reqGetGoodsDetailInfoData } from '@/api';

const state = {
    goodsDetailInfo: {}
}
const actions = {
    async getGoodsDetailInfo ({commit},skuId) {
        const result = await reqGetGoodsDetailInfoData(skuId)
        if(result.code === 200) {
            commit('SAVE_GOODS_DETAIL_INFO',result.data)
        }else {
            console.log(result.message);
        }
    }
}
const mutations = {
    // 存储商品详情数据
    SAVE_GOODS_DETAIL_INFO(state,goodsDetailInfo) {
        state.goodsDetailInfo = goodsDetailInfo
    },
    // 更改skuInfo中的放大镜图片地址
    UPDATE_SKUINFO_IMGURL(state,imgUrl){
        state.goodsDetailInfo.skuInfo.skuDefaultImg = imgUrl
    }
}
const getters = {
    categoryView(state) {
        return state.goodsDetailInfo.categoryView || {};
    },
    skuInfo(state) {
        return state.goodsDetailInfo.skuInfo || {};
    },
    spuSaleAttrList(state) {
        return state.goodsDetailInfo.spuSaleAttrList || {};
    }
}

export default {
    namespaced: true,
    state,
    actions,
    mutations,
    getters
}